const square = (v) => v * v;
const double = (v) => v * 2;
const addOne = (v) => v + 1;
function pipe(...funcArray) {
  return function (...args) {
    return funcArray.reduce((last, cur) =>
      cur(typeof last === "function" ? last.apply(last, args) : last)
    );
  };
}
var pipe = (...funcArray) => (...args) =>
  funcArray.reduce((last, cur) =>
    cur(typeof last === "function" ? last.apply(last, args) : last)
  );
const res = pipe(square, double, addOne);
console.log(res(3)); // 19; addOne(double(square(3)))
